<%@ page pageEncoding="UTF-8"%>
<%@ include file="../commons/head.jsp"%>

<script type="text/javascript" src="/training1-web/static/js/fileupload/vendor/jquery.ui.widget.js"></script>
<script type="text/javascript" src="/training1-web/static/js/fileupload/load-image.min.js"></script>
<script type="text/javascript" src="/training1-web/static/js/fileupload/canvas-to-blob.min.js"></script>
<script type="text/javascript" src="/training1-web/static/js/fileupload/jquery.blueimp-gallery.min.js"></script>
<script type="text/javascript" src="/training1-web/static/js/fileupload/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="/training1-web/static/js/fileupload/jquery.fileupload.js"></script>
<script type="text/javascript" src="/training1-web/static/js/fileupload/cors/jquery.xdr-transport.js"></script>
<script type="text/javascript" src="/training1-web/static/js/fileupload/jquery.fileupload-process.js"></script>
<script type="text/javascript" src="/training1-web/static/js/fileupload/jquery.fileupload-validate.js"></script>


<title>每日打款导入</title>
<style>
.spanButton {
	width:114px;
	height:32px;	
	margin-left:-1px;
	padding-left: 0;
	float:left;
	font-family:Arial, Helvetica, sans-serif; 
	font-size:18px;
	line-height:32px;
	text-align:center;
	text-transform:uppercase;
}
span .l-btn-icon {
	margin-top: -12px;
}
td {
	padding-top: 5px;
	padding-bottom: 5px;
	padding-right: 5px;
}

td:first-child {
	padding-left: 5px;
	padding-right: 0;
}

p {
	width:auto;
      margin-left:1px;
      float:left;
      font-family:Arial, Helvetica, sans-serif; 
      font-size:18px;
      line-height:35px;
      text-transform:uppercase;
      text-align:justify;
}

.success {
	color: green;
	font-style: normal;
	font-weight: bold;
}
.file { position:absolute; left:90px; top:8px; display:none;filter:alpha(opacity=0);opacity:0} 
.file1 { padding:2px 10px; display:block; float:left; background:#FF66CC; color:#fff; z-index:1; margin-left:5px; vertical-align:middle; cursor: pointer}

</style>

</head>

<body>
<div class="jianju">
<h3>每日打款导入</h3>
	<div style="margin: 20px 0;"></div>
	<div id="buttonDiv" style="width: 400px; padding: 30px 70px 50px 70px;" >
		
		<div style="margin-bottom: 20px;margin-left:30px;width:300px">
			<a href="${pageContext.request.contextPath}/static/禄宝通每日打款导入.xlsx"  class="easyui-linkbutton" style="font-weight:bold;"><span class="spanButton">模板下载</span></a>
		</div>
		<div style="margin-bottom: 20px;margin-left:30px;width:300px">
			<input type="file" class="file" id="file1" name="file" style="width: 74px">
			<label for="file1" onmouseover="document.getElementById('file1').style.display='block';" class="easyui-linkbutton"><span class="spanButton">文件上传</span></label> 
		</div>
		
		<div id="dlg-buttons">
			<hr style="width:174px" SIZE=2>
			<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="javascript:insert()"  style="width:100px;height:35px;font-size:30px;font-style:center;padding-top:7px;margin-left:40px;">打款导入</a>
		</div>
		
	</div>
	<div style="padding: 30px 70px 50px 70px" >
			<p id="error"></p>
	</div>
	<div style="padding: 1px 70px 50px 70px" >
			<p id="error1"></p>
	</div>
</div>
<script>
var flag =false;
var loginAccount = 'baidd';
var path;
	$("#file1").fileupload({
		iframe : true,
		url : '${ctx}/dailycharge/xlsx',
		maxFileSize : 2097152, //(最大2M)字节
		acceptFileTypes : /\.xlsx/,
		maxNumberofFiles : 1,
	}).on('fileuploadprocessalways', function(e, data) {
		if (data.files.error) {
			console.log(data.files);
			if ('File is too large' == data.files[0].error) {
				alert("文件大小不能超过2M");
			} else if ('File type not allowed' == data.files[0].error) {
				alert("上传的文件格式必须为xlsx");
			}
		} else {debugger
			data.submit();
		}
	}).on('fileuploaddone',function(e,data){
		if (data.result.result=="err") {
			$('#error').text(data.result.errMsg);
			$('#error1').text("");
		}else{
			flag=true;
			$('#error').text("");
			$('#error1').text(data.result.success1);
			path =data.result.url;
			$.messager.alert("成功","上传成功","info");
		}
	});
	
	function insert(){
		if(!flag){
			$.messager.alert("注意","请先成功上传","error");
			return;
		}
		$.messager.confirm("确定导入","确定要打款导入吗?",function(r){
			if(r){
				$.ajax({
					url:"${ctx}/dailycharge/charge",
					cache:false,
					data:{"path":path,"loginAccount":loginAccount},
					success:function(data){
						if(data.err==null){
							flag =false;
							$('#error').text(data.success);
							$('#error1').text(data.success1);
							$.messager.alert("成功","操作成功","info");
						}else{
							$('#error').text(data.err.err);
						}
					}
				});
			}
		});
	};
</script>
</body>
</html>